﻿using System.Runtime.InteropServices;
using UtilZ.Dotnet.AudioPlayer.Native;

namespace UtilZ.Dotnet.AudioPlayer.Recorder
{
    /// <summary>
    /// 录音设备信息
    /// </summary>
    public class RecordDeviceInfo
    {
        /// <summary>
        /// 设备标识
        /// </summary>
        public int DeviceId { get; private set; }

        /// <summary>
        /// 设备名称
        /// </summary>
        public string DeviceName { get; private set; }

        /// <summary>
        /// 放设备驱动名称
        /// </summary>
        public string DriverName { get; private set; }

        /// <summary>
        /// Bass设备状态标识
        /// </summary>
        public BASSDeviceInfo Flags { get; private set; }

        /// <summary>
        /// Bass设备状态
        /// </summary>
        public BASSDeviceInfo Status { get; private set; }

        /// <summary>
        /// 是否是默认设备
        /// </summary>
        public bool IsDefault { get; private set; }

        /// <summary>
        /// 该设备是否启用
        /// </summary>
        public bool IsEnabled { get; private set; }

        /// <summary>
        /// 该设备已初始化
        /// </summary>
        public bool IsInitialized { get; private set; }

        /// <summary>
        /// 设备类型
        /// </summary>
        public BASSDeviceInfo Type { get; private set; }




        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="deviceId">播放设备标识</param>
        /// <param name="bassDeviceInfo">Bass播放设备信息</param>
        internal RecordDeviceInfo(int deviceId, ref BASS_DEVICEINFO_INTERNAL bassDeviceInfo)
        {
            this.DeviceId = deviceId;
            this.DriverName = Marshal.PtrToStringAnsi(bassDeviceInfo.driver);
            this.DeviceName = Marshal.PtrToStringAnsi(bassDeviceInfo.name);
            this.Flags = bassDeviceInfo.flags;
            this.Status = (BASSDeviceInfo)((int)bassDeviceInfo.flags & 0xffffff);
            this.IsDefault = ((bassDeviceInfo.flags & BASSDeviceInfo.BASS_DEVICE_DEFAULT) > BASSDeviceInfo.BASS_DEVICE_NONE);
            this.IsEnabled = ((bassDeviceInfo.flags & BASSDeviceInfo.BASS_DEVICE_ENABLED) > BASSDeviceInfo.BASS_DEVICE_NONE);
            this.IsInitialized = ((bassDeviceInfo.flags & BASSDeviceInfo.BASS_DEVICE_INIT) > BASSDeviceInfo.BASS_DEVICE_NONE);
            this.Type = (BASSDeviceInfo)((int)bassDeviceInfo.flags & -16777216);
        }


        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return this.DeviceName;
        }
    }
}
